import iosBridge from './hybrid.js'
import androidBridge from './webView.js'

const isIOS = () => /iPhone|iPad|iPod/i.test(navigator.userAgent)
const isAndroid = () => /Android/i.test(navigator.userAgent)

const getPlatformBridge = () => {
  if (isIOS()) return iosBridge
  if (isAndroid()) return androidBridge
  console.warn('Unsupported platform, using iOS bridge as fallback')
  return iosBridge
}

// 统一导出所有方法
export default {
  getUserInfo(...args) {
    return getPlatformBridge().getUserInfo(...args)
  },
  closeWebView(...args) {
    return getPlatformBridge().closeWebView(...args)
  },
  navigateBackTo(...args) {
    return getPlatformBridge().navigateBackTo(...args)
  },
  setNavigationBarVisible(...args) {
    return getPlatformBridge().setNavigationBarVisible(...args)
  },
  getLocation() {
    const bridge = getPlatformBridge()
    if (isIOS()) {
      return bridge.getLocation()
    } else if (isAndroid()) {
      return new Promise((resolve) => {
        bridge.getLocation(resolve) // 将回调转为 Promise
      })
    }
  },
  phoneFunc(...args) {
    return getPlatformBridge().phoneFunc(...args)
  }
}
